#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
struct student
{
	int sex;
	char name[8];
	int x;
};
int main()
{
	struct student stu[50];
	int n;
	scanf("%d", &n);
	int i, j;
	for (i = 0; i < n; i++)
	{
		scanf("%d %s", &stu[i].sex, &stu[i].name);
		stu[i].x = 0;
	}
	for (i = 0; i < n; i++)
	{
		if (stu[i].x)
		{
			continue;
		}
		for (j = n - 1; j > i; j--)
		{
			if (!stu[j].x && stu[j].sex!=stu[i].sex)
			{
				printf("%s %s\n", stu[i].name, stu[j].name);
				stu[i].x = 1;
				stu[j].x = 1;
				break;
			}
		}
	}
	return 0;
}